package com.spring.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;

@Service
public class ThreadPoolService {


    @Resource
    private ExecutorService workerThreadPool;

    public void test2(){
        workerThreadPool.execute(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("ThreadPoolService 线程池执行");
        });
        System.out.println("ThreadPoolService test2 finish");
    }

    @Async("workerThreadPool")
    public void testAsync(){

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(" ThreadPoolService async");
    }
}
